#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int getmax(int a, int b) {
    return (a > b) ? a : b;
}

int dp_solve(int* arr,int len){
    int dp[len],max=0;
    for(int i=0;i<len;i++){
        dp[i]=1;
        for(int j=0;j<i;j++){
            if(arr[j]<arr[i]){
                dp[i]=getmax(dp[i],dp[j]+1);
            }
        }
        max=getmax(max,dp[i]);
    }
    return max;
}

int main(){
    int n;
    scanf("%d",&n);
    while(n--){
        char instr[1002],str[1000];
        scanf("%s",instr);
        sscanf(instr,"[%s]",str);
        char *p = strtok(str, ",");
        int arr[200],index=0;
        while(p) {
            arr[index++] = atoi(p);
            p = strtok(NULL,","); 
        }
        int result=dp_solve(arr,index);
        printf("%d\n",result);
    }
    return 0;
}